package com.cysyz.mylib.dao.sqloperaterrevolver.impl;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by cy on 2014/7/29.
 */
public class BigEqualOperatorRevolver extends BaseSqlOperatorRevolver {
    @Override
    public void addCond(StringBuilder sqlBuilder, List<Object> params, String column, String operator, Object value) {
        if (value != null && (value instanceof String || value instanceof Number)) {
            if (value instanceof String ) {
                String castedValue = (String) value;
                if (castedValue.trim().equals("-")) {
                    return;
                }
                if (castedValue.matches("[\\d]+")) {
                    value = Integer.parseInt(castedValue);
                } else if (castedValue.matches("[\\d]+\\.[\\d]+")) {
                    value = Double.parseDouble(castedValue);
                }
            }
            super.addOneCond(sqlBuilder, params, column, operator, value);
        } else {
            throw new RuntimeException(">= operator just support String or number");
        }
    }


    @Override
    protected List<String> getSupportOperatorList() {
        List<String> supportList = new ArrayList<String>();
        supportList.add(">=");
        return supportList;
    }


}
